/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jFPessoaJuridica.java
 *
 * Created on 07/08/2012, 00:23:14
 */

package ecommercial;

import ecommercial.Classes.Atividades;
import ecommercial.Classes.ClassConecta;
import ecommercial.Classes.ComboItem;
import ecommercial.Classes.Funcoes;
import ecommercial.Classes.PessoaJuridica;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author vitiazze
 */
public class jFPessoaJuridica extends javax.swing.JDialog {

    /** Creates new form jFPessoaJuridica */
    public jFPessoaJuridica() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        buscarjButton = new javax.swing.JButton();
        novojButton = new javax.swing.JButton();
        editarjButton = new javax.swing.JButton();
        salvarjButton = new javax.swing.JButton();
        salvarMaisjButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        alterarjButton = new javax.swing.JButton();
        excluirjButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        sairjButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        razaoSocialjTextField = new javax.swing.JTextField();
        cnpjjFormattedTextField = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        fantasiajTextField = new javax.swing.JTextField();
        atividadejComboBox = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        atualizaAtividadejButton = new javax.swing.JButton();
        atividadejButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        verificaCnpjjCheckBox = new javax.swing.JCheckBox();
        datAberturajFormattedTextField = new javax.swing.JFormattedTextField();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        gradePessoaJuridicajTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ecommercial.EcommercialApp.class).getContext().getResourceMap(jFPessoaJuridica.class);
        jToolBar1.setBackground(resourceMap.getColor("jToolBar1.background")); // NOI18N
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        buscarjButton.setBackground(resourceMap.getColor("buscarjButton.background")); // NOI18N
        buscarjButton.setIcon(resourceMap.getIcon("buscarjButton.icon")); // NOI18N
        buscarjButton.setText(resourceMap.getString("buscarjButton.text")); // NOI18N
        buscarjButton.setFocusable(false);
        buscarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buscarjButton.setName("buscarjButton"); // NOI18N
        buscarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        buscarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(buscarjButton);

        novojButton.setBackground(resourceMap.getColor("novojButton.background")); // NOI18N
        novojButton.setIcon(resourceMap.getIcon("novojButton.icon")); // NOI18N
        novojButton.setText(resourceMap.getString("novojButton.text")); // NOI18N
        novojButton.setFocusable(false);
        novojButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        novojButton.setName("novojButton"); // NOI18N
        novojButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        novojButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                novojButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(novojButton);

        editarjButton.setBackground(resourceMap.getColor("editarjButton.background")); // NOI18N
        editarjButton.setIcon(resourceMap.getIcon("editarjButton.icon")); // NOI18N
        editarjButton.setText(resourceMap.getString("editarjButton.text")); // NOI18N
        editarjButton.setFocusable(false);
        editarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        editarjButton.setName("editarjButton"); // NOI18N
        editarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        editarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(editarjButton);

        salvarjButton.setBackground(resourceMap.getColor("salvarjButton.background")); // NOI18N
        salvarjButton.setIcon(resourceMap.getIcon("salvarjButton.icon")); // NOI18N
        salvarjButton.setText(resourceMap.getString("salvarjButton.text")); // NOI18N
        salvarjButton.setFocusable(false);
        salvarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarjButton.setName("salvarjButton"); // NOI18N
        salvarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarjButton);

        salvarMaisjButton.setBackground(resourceMap.getColor("salvarMaisjButton.background")); // NOI18N
        salvarMaisjButton.setIcon(resourceMap.getIcon("salvarMaisjButton.icon")); // NOI18N
        salvarMaisjButton.setText(resourceMap.getString("salvarMaisjButton.text")); // NOI18N
        salvarMaisjButton.setFocusable(false);
        salvarMaisjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        salvarMaisjButton.setName("salvarMaisjButton"); // NOI18N
        salvarMaisjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        salvarMaisjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvarMaisjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(salvarMaisjButton);

        jSeparator1.setName("jSeparator1"); // NOI18N
        jToolBar1.add(jSeparator1);

        alterarjButton.setBackground(resourceMap.getColor("alterarjButton.background")); // NOI18N
        alterarjButton.setIcon(resourceMap.getIcon("alterarjButton.icon")); // NOI18N
        alterarjButton.setText(resourceMap.getString("alterarjButton.text")); // NOI18N
        alterarjButton.setFocusable(false);
        alterarjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        alterarjButton.setName("alterarjButton"); // NOI18N
        alterarjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        alterarjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(alterarjButton);

        excluirjButton.setBackground(resourceMap.getColor("excluirjButton.background")); // NOI18N
        excluirjButton.setIcon(resourceMap.getIcon("excluirjButton.icon")); // NOI18N
        excluirjButton.setText(resourceMap.getString("excluirjButton.text")); // NOI18N
        excluirjButton.setFocusable(false);
        excluirjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        excluirjButton.setName("excluirjButton"); // NOI18N
        excluirjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        excluirjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(excluirjButton);

        jSeparator2.setName("jSeparator2"); // NOI18N
        jToolBar1.add(jSeparator2);

        sairjButton.setBackground(resourceMap.getColor("sairjButton.background")); // NOI18N
        sairjButton.setIcon(resourceMap.getIcon("sairjButton.icon")); // NOI18N
        sairjButton.setText(resourceMap.getString("sairjButton.text")); // NOI18N
        sairjButton.setFocusable(false);
        sairjButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        sairjButton.setName("sairjButton"); // NOI18N
        sairjButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        sairjButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sairjButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(sairjButton);

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setForeground(resourceMap.getColor("jLabel2.foreground")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        razaoSocialjTextField.setText(resourceMap.getString("razaoSocialjTextField.text")); // NOI18N
        razaoSocialjTextField.setName("razaoSocialjTextField"); // NOI18N

        try {
            cnpjjFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        cnpjjFormattedTextField.setName("cnpjjFormattedTextField"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setForeground(resourceMap.getColor("jLabel3.foreground")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        fantasiajTextField.setText(resourceMap.getString("fantasiajTextField.text")); // NOI18N
        fantasiajTextField.setName("fantasiajTextField"); // NOI18N

        atividadejComboBox.setName("atividadejComboBox"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        atualizaAtividadejButton.setIcon(resourceMap.getIcon("atualizaAtividadejButton.icon")); // NOI18N
        atualizaAtividadejButton.setText(resourceMap.getString("atualizaAtividadejButton.text")); // NOI18N
        atualizaAtividadejButton.setContentAreaFilled(false);
        atualizaAtividadejButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atualizaAtividadejButton.setName("atualizaAtividadejButton"); // NOI18N
        atualizaAtividadejButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaAtividadejButtonActionPerformed(evt);
            }
        });

        atividadejButton.setIcon(resourceMap.getIcon("atividadejButton.icon")); // NOI18N
        atividadejButton.setText(resourceMap.getString("atividadejButton.text")); // NOI18N
        atividadejButton.setContentAreaFilled(false);
        atividadejButton.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        atividadejButton.setName("atividadejButton"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        verificaCnpjjCheckBox.setText(resourceMap.getString("verificaCnpjjCheckBox.text")); // NOI18N
        verificaCnpjjCheckBox.setName("verificaCnpjjCheckBox"); // NOI18N
        verificaCnpjjCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verificaCnpjjCheckBoxActionPerformed(evt);
            }
        });

        try {
            datAberturajFormattedTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        datAberturajFormattedTextField.setName("datAberturajFormattedTextField"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(fantasiajTextField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(razaoSocialjTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING))
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel3)
                                .addComponent(cnpjjFormattedTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                .addComponent(atividadejComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(atividadejButton, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(atualizaAtividadejButton, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(verificaCnpjjCheckBox)))
                    .addComponent(jLabel5)
                    .addComponent(datAberturajFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(atividadejButton)
                        .addComponent(atualizaAtividadejButton))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(razaoSocialjTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cnpjjFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(verificaCnpjjCheckBox))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(fantasiajTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(atividadejComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(datAberturajFormattedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel3.setName("jPanel3"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        gradePessoaJuridicajTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "#Id", "Razão Social", "CNPJ"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        gradePessoaJuridicajTable.setName("gradePessoaJuridicajTable"); // NOI18N
        gradePessoaJuridicajTable.getTableHeader().setReorderingAllowed(false);
        gradePessoaJuridicajTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                gradePessoaJuridicajTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(gradePessoaJuridicajTable);
        gradePessoaJuridicajTable.getColumnModel().getColumn(0).setResizable(false);
        gradePessoaJuridicajTable.getColumnModel().getColumn(0).setPreferredWidth(10);
        gradePessoaJuridicajTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("gradePessoaJuridicajTable.columnModel.title0")); // NOI18N
        gradePessoaJuridicajTable.getColumnModel().getColumn(1).setResizable(false);
        gradePessoaJuridicajTable.getColumnModel().getColumn(1).setPreferredWidth(300);
        gradePessoaJuridicajTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("gradePessoaJuridicajTable.columnModel.title1")); // NOI18N
        gradePessoaJuridicajTable.getColumnModel().getColumn(2).setResizable(false);
        gradePessoaJuridicajTable.getColumnModel().getColumn(2).setPreferredWidth(80);
        gradePessoaJuridicajTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("gradePessoaJuridicajTable.columnModel.title2")); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 603, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    ClassConecta conexao = new ClassConecta();

    int cod_pessoa_juridica;

    ComboItem comboAtividade;


     public void getGrandePessoaJuridica() throws ParseException{
       //Consultar pedidos
        PessoaJuridica oPessoaJuridica = new PessoaJuridica();

        ResultSet resultSet = null;

        String[] colunasTabela = new String[]{"Id#", "Razão Social", "CNPJ"};
        DefaultTableModel modeloTabela = new DefaultTableModel(null, colunasTabela) {

            @Override
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };
        gradePessoaJuridicajTable.setModel(modeloTabela);
        gradePessoaJuridicajTable.getColumnModel().getColumn(0).setPreferredWidth(10);
        gradePessoaJuridicajTable.getColumnModel().getColumn(1).setPreferredWidth(300);
        gradePessoaJuridicajTable.getColumnModel().getColumn(2).setPreferredWidth(80);

try {
            oPessoaJuridica.setCod_pessoa(cod_pessoa_juridica);

            resultSet = oPessoaJuridica.getConsultar();

            if (resultSet.getRow() == 1){
             resultSet.first();
            }


        } catch (SQLException ex) {
            Logger.getLogger(PessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {

            while (resultSet.next()) {

                modeloTabela.addRow(new String[]{
                    Funcoes.getCodigoFormat(resultSet.getInt("COD_PESSOA")),
                    resultSet.getString("RAZAO_SOCIAL"),
                    resultSet.getString("CNPJ") ,
                });

            }

        } catch (SQLException ex) {
            Logger.getLogger(PessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }

           }

     public void getFieldPessoaJuridica(int cod_pessoa_juridica) throws ParseException{

        PessoaJuridica oPessoaJuridica = new PessoaJuridica();
        ResultSet rs = null;
        oPessoaJuridica.setCod_pessoa(cod_pessoa_juridica);

        try {
            rs = oPessoaJuridica.getConsultar();
            rs.next();

            //Pegar campos
            ComboItem oItem = new ComboItem(rs.getInt("COD_ATIVIDADE"), rs.getString("ATIVIDADE"));
            atividadejComboBox.setSelectedItem(oItem);

            razaoSocialjTextField.setText(rs.getString("RAZAO_SOCIAL"));
            cnpjjFormattedTextField.setText(rs.getString("CNPJ"));
            fantasiajTextField.setText(rs.getString("FANTASIA"));
            atividadejComboBox.setSelectedItem("ATIVIDADE");
            datAberturajFormattedTextField.setValue(Funcoes.getDataFormat(rs.getDate("DAT_ABERTURA")));

        } catch (SQLException ex) {
            Logger.getLogger(PessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    private void sairjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sairjButtonActionPerformed
        // TODO add your handling code here:
        if (!novojButton.isEnabled()){
                Object[] options = {"Sim", "Não"};
                int sd = JOptionPane.showOptionDialog(null, "Deseja realmente SAIR?", "Confirmação do Sistema!", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                if (sd != 0) {
                    return;
                }

                this.dispose();

            }else{

                this.dispose();

            }
    }//GEN-LAST:event_sairjButtonActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        ClassConecta.conecta();

        salvarjButton.setEnabled(false);
        salvarMaisjButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        novojButton.setEnabled(true);
        razaoSocialjTextField.grabFocus();

        atualizaAtividadejButtonActionPerformed(null);
        buscarjButtonActionPerformed(null);
    }//GEN-LAST:event_formWindowOpened

    private void atualizaAtividadejButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaAtividadejButtonActionPerformed
        // TODO add your handling code here:
        try {
            Atividades oAtividade = new Atividades();
            ResultSet rs = null;
            rs = oAtividade.getConsultar();
            atividadejComboBox.removeAllItems();
            while (rs.next()) {
                atividadejComboBox.addItem(new ComboItem(rs.getInt("COD_ATIVIDADE"), rs.getString("ATIVIDADE")));
            }
            atividadejComboBox.updateUI();
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_atualizaAtividadejButtonActionPerformed

    private void buscarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarjButtonActionPerformed
        // TODO add your handling code here:

        atualizaAtividadejButtonActionPerformed(null);
        try {
            getGrandePessoaJuridica();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buscarjButtonActionPerformed

    private void novojButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_novojButtonActionPerformed
        // TODO add your handling code here:
        novojButton.setEnabled(false);
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(false);
        excluirjButton.setEnabled(false);
        buscarjButton.setEnabled(true);
        salvarjButton.setEnabled(true);
        salvarMaisjButton.setEnabled(true);
        razaoSocialjTextField.grabFocus();
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFEstados.class.getName()).log(Level.SEVERE, null, ex);
        }
        razaoSocialjTextField.setText("");
        cnpjjFormattedTextField.setText("");
        fantasiajTextField.setText("");
        atualizaAtividadejButtonActionPerformed(null);
        datAberturajFormattedTextField.setText("");

    }//GEN-LAST:event_novojButtonActionPerformed

    private void verificaCnpjjCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verificaCnpjjCheckBoxActionPerformed
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "Esta função esta indisponivel no momento", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_verificaCnpjjCheckBoxActionPerformed

    private void salvarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarjButtonActionPerformed
        // TODO add your handling code here:
            salvarjButton.setEnabled(false);
            salvarMaisjButton.setEnabled(false);
            alterarjButton.setEnabled(false);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);
            editarjButton.setEnabled(true);

            comboAtividade = (ComboItem) atividadejComboBox.getSelectedItem();


            PessoaJuridica oPessoaJuridica = new PessoaJuridica();

            

            if(razaoSocialjTextField.getText().equals("")){

                JOptionPane.showMessageDialog(null, "O campo Razão Social é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);

            }else if(cnpjjFormattedTextField.getText().equals("  .   .   /    -  ")){

                JOptionPane.showMessageDialog(null, "O campo CNPJ é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else{
            try {
                oPessoaJuridica.setCod_pessoa(cod_pessoa_juridica);
                oPessoaJuridica.setRazao_social(razaoSocialjTextField.getText().trim().toUpperCase());
                oPessoaJuridica.setCnpj(cnpjjFormattedTextField.getText());
                oPessoaJuridica.setFantasia(fantasiajTextField.getText());
                oPessoaJuridica.setCod_atividade(comboAtividade.getId());
                if(datAberturajFormattedTextField.getText().equals("  /  /    ")){
                    datAberturajFormattedTextField.setText("");
                }else{
                oPessoaJuridica.setDatAbertura(Funcoes.getDataFormatBR(datAberturajFormattedTextField.getText()));
            } }catch (ParseException ex) {
                Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
            }
                oPessoaJuridica.setCadastrar();
            try {
                ClassConecta.con.commit();
                ClassConecta.con.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
        try {
            getGrandePessoaJuridica();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_salvarjButtonActionPerformed

    private void gradePessoaJuridicajTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_gradePessoaJuridicajTableMouseClicked
        // TODO add your handling code here:
        editarjButton.setEnabled(true);
            cod_pessoa_juridica = Integer.parseInt(gradePessoaJuridicajTable.getValueAt(gradePessoaJuridicajTable.getSelectedRow(), 0).toString());
            if (cod_pessoa_juridica == 0) {
                return;
            }
        try {
            getFieldPessoaJuridica(cod_pessoa_juridica);
        } catch (ParseException ex) {
            Logger.getLogger(jFTelefones.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_gradePessoaJuridicajTableMouseClicked

    private void editarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editarjButtonActionPerformed
        // TODO add your handling code here:
            novojButton.setEnabled(false);
            salvarjButton.setEnabled(false);
            editarjButton.setEnabled(false);
            alterarjButton.setEnabled(true);
            excluirjButton.setEnabled(true);
        try {
            ClassConecta.con.setAutoCommit(false);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_editarjButtonActionPerformed

    private void alterarjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarjButtonActionPerformed
        // TODO add your handling code here:
            alterarjButton.setEnabled(false);
            editarjButton.setEnabled(true);
            excluirjButton.setEnabled(false);
            novojButton.setEnabled(true);

            PessoaJuridica oPessoaJuridica = new PessoaJuridica();

            comboAtividade = (ComboItem) atividadejComboBox.getSelectedItem();

             if(razaoSocialjTextField.getText().equals("")){

                JOptionPane.showMessageDialog(null, "O campo Razão Social é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);

            }else if(cnpjjFormattedTextField.getText().equals("  .   .   /    -  ")){

                JOptionPane.showMessageDialog(null, "O campo CNPJ é obrigatório", "ATENÇÃO Mensagem do Sistema", JOptionPane.INFORMATION_MESSAGE);
            }else{
            try {
                oPessoaJuridica.setCod_pessoa(cod_pessoa_juridica);
                oPessoaJuridica.setRazao_social(razaoSocialjTextField.getText().trim().toUpperCase());
                oPessoaJuridica.setCnpj(cnpjjFormattedTextField.getText());
                oPessoaJuridica.setFantasia(fantasiajTextField.getText());
                oPessoaJuridica.setCod_atividade(comboAtividade.getId());
                if(datAberturajFormattedTextField.getText().equals("  /  /    ")){
                    datAberturajFormattedTextField.setText("");
                }else{
                oPessoaJuridica.setDatAbertura(Funcoes.getDataFormatBR(datAberturajFormattedTextField.getText()));
            } }catch (ParseException ex) {
                Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
            }
                oPessoaJuridica.setAlterar(conexao);
            try {
                ClassConecta.con.commit();
                ClassConecta.con.setAutoCommit(true);
            } catch (SQLException ex) {
                Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
            }
            }
        try {
            getGrandePessoaJuridica();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoaJuridica.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_alterarjButtonActionPerformed

    private void salvarMaisjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvarMaisjButtonActionPerformed
        // TODO add your handling code here:
        salvarjButtonActionPerformed(null);
        novojButtonActionPerformed(null);
    }//GEN-LAST:event_salvarMaisjButtonActionPerformed

    private void excluirjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirjButtonActionPerformed
        // TODO add your handling code here:
        Object[] options = {"Sim", "Não"};
        int sd =
                JOptionPane.showOptionDialog(null, "Deseja realmente EXCLUIR esse registro?", "Confirmação!", JOptionPane.DEFAULT_OPTION,
                JOptionPane.WARNING_MESSAGE, null, options, options[0]);

        if (sd != 0) {
            return;
        }
        alterarjButton.setEnabled(false);
        editarjButton.setEnabled(true);
        excluirjButton.setEnabled(false);
        novojButton.setEnabled(true);

        PessoaJuridica oPessoaJuridica = new PessoaJuridica();
        oPessoaJuridica.setCod_pessoa(cod_pessoa_juridica);
        oPessoaJuridica.setExcluir(conexao);
        try {
            ClassConecta.con.commit();
            ClassConecta.con.setAutoCommit(true);
        } catch (SQLException ex) {
            Logger.getLogger(jFPessoas.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            getGrandePessoaJuridica();
        } catch (ParseException ex) {
            Logger.getLogger(jFPessoaFisica.class.getName()).log(Level.SEVERE, null, ex);
        }
        razaoSocialjTextField.setText("");
        cnpjjFormattedTextField.setText("");
        fantasiajTextField.setText("");
        atualizaAtividadejButtonActionPerformed(null);
        datAberturajFormattedTextField.setText("");
    }//GEN-LAST:event_excluirjButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jFPessoaJuridica().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton alterarjButton;
    private javax.swing.JButton atividadejButton;
    private javax.swing.JComboBox atividadejComboBox;
    private javax.swing.JButton atualizaAtividadejButton;
    private javax.swing.JButton buscarjButton;
    private javax.swing.JFormattedTextField cnpjjFormattedTextField;
    private javax.swing.JFormattedTextField datAberturajFormattedTextField;
    private javax.swing.JButton editarjButton;
    private javax.swing.JButton excluirjButton;
    private javax.swing.JTextField fantasiajTextField;
    private javax.swing.JTable gradePessoaJuridicajTable;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton novojButton;
    private javax.swing.JTextField razaoSocialjTextField;
    private javax.swing.JButton sairjButton;
    private javax.swing.JButton salvarMaisjButton;
    private javax.swing.JButton salvarjButton;
    private javax.swing.JCheckBox verificaCnpjjCheckBox;
    // End of variables declaration//GEN-END:variables

}
